#ifndef _DEF_H
#define _DEF_H

// 初始化链表头节点指针域的宏函数
#define INIT_LIST_HEAD(ptr) do { \
	(ptr)->next = (ptr); (ptr)->prev = (ptr); \
} while (0) 

/**
 *  从前向后遍历
* list_for_each    -    iterate over a list
* @pos:    the &struct list_head to use as a loop counter.
* @head:    the head for your list.
*/
#define list_for_each(pos, head) \
for (pos = (head)->next; pos != (head); \
pos = pos->next)


// /**
//  * 从后向前遍历
// * list_for_each_prev    -    iterate over a list backwards
// * @pos:    the &struct list_head to use as a loop counter.
// * @head:    the head for your list.
// */
// #define list_for_each_prev(pos, head) \
// for (pos = (head)->prev; pos != (head); \
// pos = pos->prev)

/**
    pos 是小结构体指针
    n 用来临时保存下一个节点的小结构体的指针
    head 头结点的小结构体地址&(head->my)
*/
#define list_for_each_safe(pos, n, head) \
for (pos = (head)->next, n = pos->next; pos != (head); \
pos = n, n = pos->next)

// /********往前遍历（安全模式）************/
// #define list_for_each_prev_safe(pos, n, head) \
// for (pos = (head)->prev, n = pos->prev; pos != (head); \
// pos = n, n = pos->prev)

// /**
// * list_for_each_entry    -    iterate over list of given type
// * @pos:    大结构体的节点的指针(地址)
// * @head:    节点中的小结构体的地址 &(head->my)
// * @member:   小结构体的名称 my.
// */
// #define list_for_each_entry(pos, head, member)                \
// for (pos = list_entry((head)->next, typeof(*pos), member);    \
// &pos->member != (head);                     \
// pos = list_entry(pos->member.next, typeof(*pos), member))

// #define list_for_each_entry_safe(pos, n, head, member)            \
// for (pos = list_entry((head)->next, typeof(*pos), member),    \
// n = list_entry(pos->member.next, typeof(*pos), member);    \
// &pos->member != (head);                     \
// pos = n, n = list_entry(n->member.next, typeof(*n), member))




#endif